import { Form } from "vant";
import ajax  from "./index";
// 分类  /home/category/head
export const  category = () =>{
    return ajax({
        url:'/home/category/head',
        method:'get'
    })
}
// 品牌  /home/brand

export const Brand = () =>{
    return ajax({
        url:'/home/brand',
        method:'get'
    })
}
// /home/banner
export const Banner = () =>{
    return ajax({
        url:'/home/banner',
        method:'get'
    })
}
// 新鲜好物  /home/new
export const New = () =>{
    return ajax({
        url:'/home/new',
        method:'get'
    })
}
// 人气推荐  /home/hot
export const Hot = () =>{
    return ajax({
        url:'/home/hot',
        method:'get'
    })
}
// 二级分类  /category
export const SubCategory = (id) =>{
    return ajax({
        url:'/category',
        method:'get',
        params:{id}
    })
}
// /goods
export const GoodsInfo = (id) =>{
    return ajax({
        url:'/goods',
        method:'get',
        params:{id}
    })
}
// 相似商品
export const findRelevantGoods = ( id, limit = 16 ) => {
    return ajax({
        url:'/goods/relevant', method:'get',params: { id, limit }
    })
  }
//   /member/cart
export const insertCart = ({skuId,count}) =>{
    return ajax({
        url:'/member/cart',
        method:'post',
        data:{skuId,count}
        
    })
}
// /category/sub/filter  二级类目-筛选条件-PC
export const Filter = (id) =>{
    return ajax({
        url:'/category/sub/filter',
        method:'get',
        params:{id}
        
    })
}

/**
 * 修改购物车商品（状态，数量）
 * @param {String} skuId - SKUID
 * @param {Integer} count - 加入购物车数量
 * @param {Boolean} selected - 选中状态
 * @returns
 */

export const updateCart = ({ skuId, selected, count }) => {
    return ajax({
       url: `/member/cart/${skuId}`,
       method: 'put', 
       data:{ selected, count }
    })
  }
//   /login
export const Login = ({ account, password }) =>{
    return ajax({
        url:'/login', //''里面不要有空格，回404
        method:'post',
        data:{ account, password }
    })
}

/*
**
 * 合并购物车
 * @param {Array<object>} cartList - 购物车信息列表
 * @param {String} object.skuId - SKUID
 * @param {Boolean} object.selected - 选中状态
 * @param {Integer} object.count - 数量
 */
export const mergeCart = (cartList) => {
  return ajax({
  url:'/member/cart/merge',
  method:'post', 
  data:cartList
})
}

/**
 * 获取购物车列表
 * @returns
 */
 export const findCart = () => {
    return ajax({url:'/member/cart',method: 'get'})
  }

  /**
 * 获取商品的 最新价格  库存  是否有效
 * @param {String} skuId - SKU id
 */
export const getNewCartGoods = (skuId) => {
    return ajax({url:`/goods/stock/${skuId}`, method:'get'})
  }
  
  /**
   *  获取商品对应的sku数据
   *  @param {String} skuId - SKU id
   */
  export const getGoodsSku = (skuId) => {
    returnajax({url:`/goods/sku/${skuId}`,  method:'get'})
  }
  
  /**
   * 合并购物车
   * @param {Array<object>} cartList - 购物车信息列表
   * @param {String} object.skuId - SKUID
   * @param {Boolean} object.selected - 选中状态
   * @param {Integer} object.count - 数量
   */
//   export const mergeCart = (cartList) => {
//     return request('/member/cart/merge', 'post', cartList)
//   }
  
  /**
   * 获取购物车列表
   * @returns
   */
//   export const findCart = () => {
//     return request('/member/cart', 'get')
//   }
  
  /**
   * 加入购物车
   * @param {String} skuId - SKUID
   * @param {Integer} count - 加入购物车数量
   * @returns
   */
//   export const insertCart = ({ skuId, count }) => {
//     return request('/member/cart', 'post', { skuId, count })
//   }
  
  /**
   * 删除购物车商品，支批量
   * @param {Array<string>} ids - skuId 的集合
   */
  export const deleteCart = (ids) => {
    return ajax({url:'/member/cart', method:'delete',params:{ ids }})
  }
  
  /**
   * 修改购物车商品（状态，数量）
   * @param {String} skuId - SKUID
   * @param {Integer} count - 加入购物车数量
   * @param {Boolean} selected - 选中状态
   * @returns
   */
//   export const updateCart = ({ skuId, selected, count }) => {
//     return request(`/member/cart/${skuId}`, 'put', { selected, count })
//   }
  
  /**
   * 全部选中&取消全选
   * @param {Boolean} selected - 选中状态
   * @param {Array<string>} ids - skuId 的集合
   */
  export const checkAllCart = ({ selected, ids }) => {
    return ajax({url:'/member/cart/selected',  method:'put', params:{ selected, ids }})
  }